﻿Ext.require([
    'Ext.tree.*',
    'Ext.data.*'
]);

Ext.define('workflow.models.treemodel', {
                                    extend: 'Ext.data.Model',
                                    fields: [{
                                    name: 'text',
                                    type:'string'
                                    }, {name:'id',type:'string'},{name: 'lead',type:'bool'}]
                                    
});


Ext.define('workflow.views.wftree', {
    extend: 'Ext.tree.Panel',
    alias:'widget.wftree',
    collapseDirection: 'left',
    collapsed: false,
    collapsible: true,
    title: '流程管理',
    rootVisible: true,
    root:{id:"000",text:'流程',expanded:true},
    store: Ext.create('Ext.data.TreeStore',{
	    model:'workflow.models.treemodel',
	    autoLoad: true,
        autoSync: true,
        queryMode: 'local',
        proxy: {
            type: 'ajax',
            api: {
            read: 'workflow_tree_ajax.aspx?action=read'
            },
            reader: {
                type: 'json',
                successProperty: 'success',
                root: 'data',
                messageProperty: 'message'
            },
            listeners: {
                exception: function(proxy, response, operation) {
                    Ext.MessageBox.show({
                        title: 'REMOTE EXCEPTION',
                        msg: operation.getError(),
                        icon: Ext.MessageBox.ERROR,
                        buttons: Ext.Msg.OK
                    });
                }
            }
        }
     
    }),//treestore,

    initComponent: function() {
        var me = this;

        Ext.applyIf(me, {
            viewConfig: {

            }
        });

        me.callParent(arguments);
    },
    listeners : {  
        afterrender: function (tree) {
              tree.getSelectionModel()
         },
        itemclick : function(view,re){  
            treeClick(re.data);
            Ext.getCmp('com_source_1').setDisabled(false);
           
        },
        load: function(obj){
            this.getSelectionModel().select(1);
            treeClick(Ext.getCmp('wftree1').getRootNode().firstChild.data);
           //this.fireEvent('itemclick',Ext.getCmp('wftree1').getRootNode().firstChild);
        }
    }  
});

var treeClick=function(data)
{
    if(data.id=='100' || data.id=='101')
            {
                Ext.getCmp('mainform1').setTitle('隐患排查治理档案表--'+data.text);
                Ext.getCmp('mainform1').setVisible(true);
                Ext.getCmp('tasklist1').setVisible(false);
            }
            else{
                Ext.getCmp('tasklist1').setTitle('任务列表--'+data.text);
                Ext.getCmp('mainform1').setVisible(false);
                Ext.getCmp('tasklist1').setVisible(true);
            Ext.getCmp('tasklist1').store.load({
                 params: {
                              wfid: data.id
                         }
            }); 
             }
}; 


